package com.yxw.springmvc.userBehavior.controller;

import com.yxw.springmvc.userBehavior.model.User;
import com.yxw.springmvc.userBehavior.request.UserLoginRequest;
import com.yxw.springmvc.userBehavior.request.UserRegistRequest;
import com.yxw.springmvc.userBehavior.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 用户控制器
 * Author: Terence
 * Date:   2014/10/13
 * Time:   14:14
 */
@Controller
@RequestMapping("/user")
public class UserController {
    private Logger logger = Logger.getLogger(UserController.class);

    @Resource
    private UserService userService;

    @RequestMapping("/findUserInfo")
    @ResponseBody
    public User findUserInfo(){
        User user = userService.findUserInfo();
        if(user != null){
            logger.info(user);
            System.out.println(user);
        }
        return user;
    }

    @RequestMapping("/register")
    @ResponseBody
    public User register(UserRegistRequest request){
        User user = userService.register(request.getName(),request.getFile());
        return user;
    }

    @RequestMapping("/login")
    @ResponseBody
    public User login (UserLoginRequest request){
        //查询用户
        User user = userService.login(request.getUserCode(),request.getUserPwd(),request.getRandomCode());
        return user;
    }

}
